package org.teamforce.demo2;

import android.os.Bundle;
import android.app.Activity;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.util.Log;
import android.view.View;
import android.os.AsyncTask;
import org.teamforce.demo2.R;
import org.teamforce.demo2.Constants.DlgType;

public class MainActivity extends Activity {
	private AsynchWorker bgTask;

	@Override
	protected final void onCreate(final Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		PackageInfo pInfo;
		try {
			pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
			this.setTitle(pInfo.versionName);
		} catch (NameNotFoundException e) {
			Log.d("Main activity", "it is an error bud");
		}
		
	}

	public final void commandListener(final View target) {
		switch (target.getId()) {
		case R.id.runActivity:
			bgTask = new AsynchWorker(DlgType.activityIndicator, this);
			bgTask.execute("Good", "Bad", "Ugly");
			break;

		case R.id.runProgress:
			bgTask = new AsynchWorker(DlgType.progressIndicator, this);
			bgTask.execute("Good", "Bad", "Ugly");
			break;
			
		default:
			Log.d("Main activity", "it is an error bud");
			break;
		}		
	}

	@Override
	protected final void onPause() {

		if ((bgTask != null)
				&& (bgTask.getStatus() == AsyncTask.Status.RUNNING)) {
			bgTask.cancel(false);
		}
		super.onPause();
	}



}
